package com.bw.baserecyclerview.diff;

import android.util.Log;
import androidx.recyclerview.widget.DiffUtil;
import java.util.List;

public class DiffAdapterCallBack extends DiffUtil.Callback {

    private List<DiffEntity> sourceList;
    private List<DiffEntity>list;

    public DiffAdapterCallBack( List<DiffEntity> sourceList,List<DiffEntity>list){
        this.sourceList = sourceList;
        this.list = list;
    }

    @Override
    public int getOldListSize() {
        return sourceList.size();
    }

    @Override
    public int getNewListSize() {
        return list.size();
    }
    //areItemsTheSame方法返回false->id不同->数据不同
    //->返回true->areContentsTheSame比较实体类中的内容
    //比较id标识
    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        boolean flag = sourceList.get(oldItemPosition).id == list.get(newItemPosition).id;
        Log.e("ZXY","areItemsTheSame"+flag);
        return flag;
    }
    //比较内容
    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        boolean flag = sourceList.get(oldItemPosition).title.equals(list.get(newItemPosition).title);
        Log.e("ZXY","areContentsTheSame"+flag);
        return flag;
    }
}
